package cn.iocoder.yudao.module.member.assets.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.api.member.assets.dto.MemberDigitalAssetsRespDTO;
import cn.iocoder.yudao.module.member.assets.convert.MemberDigitalAssetsConvert;
import cn.iocoder.yudao.module.member.assets.dal.dataobject.MemberDigitalAssetsDO;
import cn.iocoder.yudao.module.member.assets.service.AppMemberDigitalAssetsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 数字资产")
@RestController
@RequestMapping("/member/digital-assets")
@Validated
public class MemberDigitalAssetsController {
    @Resource
    private AppMemberDigitalAssetsService appMemberDigitalAssetsService;

    @PreAuthorize("@ss.hasPermission('member:digital-assets:query')")
    @GetMapping("/get-by-user-id")
    @Operation(summary = "详情（按用户编号）")
    public CommonResult<MemberDigitalAssetsRespDTO> getDetailByUserId(@RequestParam("userId") Long userId) {
        MemberDigitalAssetsDO digitalAssetsDO = appMemberDigitalAssetsService.getOrCreate(userId);
        return success(MemberDigitalAssetsConvert.INSTANCE.convert(digitalAssetsDO));
    }

}